package com.yehebl.orm.data.common;

import com.yehebl.orm.config.IConfig;
import com.yehebl.orm.dto.ClassInfo;
import com.yehebl.orm.exception.ClassNotEntityException;
import com.yehebl.orm.manager.ReadClassManager;

import java.util.Collection;

public abstract class CommonDao implements IDao {
	
	protected IConfig config;

	public CommonDao(IConfig config) {
		setConfig(config);
	}


	protected ClassInfo getClassInfo(Class<?> clazz) {
		ClassInfo classInfo = ReadClassManager.map.get(clazz.getName());
		if (classInfo == null) {
			throw new ClassNotEntityException(clazz);
		}
		return classInfo;
	}

	protected <T> ClassInfo getClassInfo(Collection<T> collection) {
		for (T t : collection) {
			return getClassInfo(t.getClass());
		}
		return null;
	}

	@Override
	public IConfig getConfig() {
		return config;
	}

	public void setConfig(IConfig config) {
		this.config = config;
	}
	
	
	


}
